<template>
  <Model
    title="审核"
    :width="800"
    :show="show"
    @confirm="confirm"
    @cancel="cancel"
  >
    <Form slot="form">
      <FormDoubleItem :labels="['标题', '作者']">
        <a-input
          slot="left"
          :value="row.title"
          :disabled="row.checking"
          placeholder="请输入内容"
        ></a-input>
        <a-input
          slot="right"
          :value="row.author"
          placeholder="请输入内容"
          :disabled="row.checking"
        ></a-input>
      </FormDoubleItem>
      <FormDoubleItem :labels="['期刊', '发表时间']">
        <a-input
          slot="left"
          :value="row.journal"
          placeholder="请输入内容"
          :disabled="row.checking"
        ></a-input>
        <a-date-picker :disabled="row.checking" slot="right" />
      </FormDoubleItem>
      <FormDoubleItem :labels="['期刊类型', '审核']">
        <a-select
          slot="left"
          placeholder="请选择"
          show-search
          option-filter-prop="children"
          style="width: 100%"
          :value="row.type"
          :disabled="row.checking"
        >
          <a-select-option v-for="item in paperType" :value="item" :key="item">
            {{ item }}
          </a-select-option>
        </a-select>
        <a-select
          slot="right"
          show-search
          :default-value="row.check"
          placeholder="请选择"
          option-filter-prop="children"
          style="width: 100%"
          @change="onChange"
        >
          <a-select-option
            v-for="(item, i) in check"
            :disabled="i === 0"
            :key="item"
            :value="item"
          >
            {{ item }}
          </a-select-option>
        </a-select>
      </FormDoubleItem>
      <FormDoubleItem :labels="['教师', '文件']">
        <a-input
          slot="left"
          :value="row.teacherName"
          :disabled="row.checking"
          placeholder="请输入内容"
        ></a-input>
        <a-button
          slot="right"
          :disabled="!row.file"
          type="primary"
          icon="download"
          @click="download"
        >
          下载文件
        </a-button>
      </FormDoubleItem>
    </Form>
  </Model>
</template>

<script>
import Model from "components/common/model/Model";
import Form from "components/common/form/Form";
import FormItem from "components/common/form/formItem/FormItem";
import FormAlignItem from "components/common/form/formAlignItem/FormAlignItem";
import FormDoubleItem from "components/common/form/formDoubleItem/FormDoubleItem";
import { paperType, check } from "assets/data/other";
import { hasPropertyEmpty, downloadOfA } from "common/index";
import { downloadFile } from "network/t-paper";
export default {
  components: {
    Model,
    Form,
    FormDoubleItem,
    FormAlignItem,
  },
  props: {
    row: {
      type: Object,
      default() {
        return {};
      },
    },
    show: {
      type: Boolean,
      defalut: false,
    },
  },
  data() {
    return {
      paperType,
      check,
    };
  },
  methods: {
    async download() {
      if (!this.row.file) return;
      //发送请求
      const result = await downloadFile(this.row.file);
      if (!result) return;

      //下载文件
      downloadOfA(
        result,
        this.row.file,
        `${this.row.title}-${this.row.author}`
      );
    },
    onChange(value) {
      this.row.check = value;
    },
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    },
    confirm() {
      this.$emit("confirm", {
        id: this.row.id,
        check: check.indexOf(this.row.check),
      });
    },
    cancel() {
      this.$emit("cancel");
    },
  },
};
</script>

<style lang="less" scoped>
.ant-btn {
  width: 235px !important;
}
</style>